package com.school.demo.controller.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.school.demo.model.auto.Activities;
import com.school.demo.model.auto.StudentReport;
import com.school.demo.service.IStudentReportService;
import com.school.demo.util.Restful;
import com.school.demo.util.Status;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Charlotte
 * @since 2021-04-26
 */
@Controller
@Api(tags = "校友圈管理API")
@RequestMapping("/api/student-report")
public class StudentReportAPIController {

    @Autowired
    IStudentReportService studentReportService;

    /**
     * 分页获取全部校友圈
     */
    @ApiOperation(value = "分页获取全部校友圈", notes = "", tags = {})
    @RequestMapping(value = "/getList", method = RequestMethod.POST)
    public @ResponseBody
    Restful list(@RequestParam(name = "studentId", defaultValue = "1") Integer studentId, @RequestParam(name = "offset", defaultValue = "1") Integer offset, @RequestParam(name = "limmit", defaultValue = "1") Integer limmit) throws Exception {
        if (studentId<0 || offset <1 || limmit <1){
            return new Restful(Status.REQUEST_PARAMETER_ERROR);
        }
        QueryWrapper<StudentReport> sq = new QueryWrapper<>();
        sq.lambda().eq(StudentReport::getUId,studentId);

        Page<StudentReport> page = new Page<>(offset, limmit);
        Page<StudentReport> list = studentReportService.page(page,sq);
        Restful restful = new Restful(Status.SUCCESS);
        restful.setData(page);
        return restful;

    }

    }
